import Mock from 'mockjs'

var taskTemp = Mock.mock({
  'list|50': [{
    'id|+1': 1,
    'taskTmplName': '任务模板@id',
    'categoryName': '任务分类@id',
    'creatorId': '100@id',
    'creator': '@cname()',
    'createTime': '@date()',
    'categoryCode': '000@id'
  }]
})

export default [


  // 任务模板分页
  {
    url: '/task/templet/getPageList',
    type: 'post',
    response: config => {
      let { pageSize = 10, currentPage = 1 } = config.body
      const total = taskTemp.list.length
      let list = taskTemp.list.slice(pageSize * (currentPage - 1), currentPage * pageSize)
      return {
        code: 20000,
        data: {
          list,
          currentPage,
          pageSize,
          totalCount: total,
          totalPages: (total + pageSize - 1) / pageSize,
        }
      }
    }
  },
  //任务模板删除
  {
    url: '/task/templet/del',
    type: 'post',
    response: config => {
      const { id } = config.body
      if (!id) {
        return {
          code: 403,
          msg: '删除失败',
          data: null
        }
      }
      return {
        code: 20000,
        msg: '处理成功',
        data: id
      }
    }
  },
  //任务模板新增
  {
    url: '/task/templet/add',
    type: 'post',
    response: config => {
      const { taskTmplName } = config.body
      if (!taskTmplName) {
        return {
          code: 20203,
          msg: 'taskTmplName is require',
          data: null
        }
      }
      return {
        code: 20000,
        msg: '处理成功',
      }
    }
  },
  //任务模板修改
  {
    url: '/task/templet/update',
    type: 'post',
    response: config => {
      const { id, taskTmplName } = config.body
      if (!taskTmplName || !id) {
        return {
          code: 20203,
          msg: 'id and taskTmplName is require',
          data: null
        }
      }
      return {
        code: 20000,
        msg: '处理成功',
      }
    }
  },
]